package com.mmy.controller.sys;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mmy.domain.constzone.TConstZone;
import com.mmy.domain.sys.VSysOrg;
import com.mmy.service.impl.constzone.ConstZoneServiceImpl;
import com.mmy.service.impl.sys.VSysOrgServiceImpl;

@Controller
public class VSysOrgController {
	@Autowired
	VSysOrgServiceImpl vSysOrgServiceImpl;
	@Autowired
	ConstZoneServiceImpl constZoneServiceImpl;

	/* 进入公司详情 */
	@RequestMapping(value = "/orginfo")
	public String ToOrgInfo(HttpServletRequest request, Model model) {

		int iOrgID = Integer.parseInt(request.getParameter("OrgID"));

		VSysOrg vSysOrg = vSysOrgServiceImpl.findByID(iOrgID);
		model.addAttribute("newVSysOrg", vSysOrg);

		return "webbackground/sysorgmanagement/orginfo";
	}
	/* 审核公司详情 */
	@RequestMapping(value = "/orginfocheck")
	public String ToOrgInfocheck(HttpServletRequest request, Model model) {

		int iOrgID = Integer.parseInt(request.getParameter("OrgID"));

		VSysOrg vSysOrg = vSysOrgServiceImpl.findByID(iOrgID);
		model.addAttribute("newVSysOrg", vSysOrg);

		return "webbackground/sysorgmanagement/orginfocheck";
	}

	/* 搜索 */
	@RequestMapping(value = "/searchsysorg")
	public String FindSysOrg(HttpServletRequest request, Model m) {

		String strOrgName = request.getParameter("OrgName");

		String strOrgID = request.getParameter("OrgID");
		String strZoneID = request.getParameter("ZoneID");
		List<VSysOrg> db_VSysOrg = new ArrayList<VSysOrg>();

		if (strOrgName == "" && strOrgID == "" && strZoneID == "") {

			db_VSysOrg = vSysOrgServiceImpl.findAll();
		} else {
			db_VSysOrg = vSysOrgServiceImpl.findSearch(strOrgName, strOrgID, strZoneID);

		}
		m.addAttribute("newVSysOrg", db_VSysOrg);
		/* 省市区 */
		List<TConstZone> db_TConstZoneProvince = constZoneServiceImpl.findAllProvince();
		m.addAttribute("newTConstZoneProvince", db_TConstZoneProvince);
		List<TConstZone> db_TConstZone = constZoneServiceImpl.findAllCity();
		m.addAttribute("newTConstZone", db_TConstZone);
		List<TConstZone> db_TConstZoneDistrict = constZoneServiceImpl.findAllDistrict();
		m.addAttribute("newTConstZoneDistrict", db_TConstZoneDistrict);
		List<VSysOrg> db_VSysOrgAll = vSysOrgServiceImpl.findAll();
		m.addAttribute("newVSysOrgAll", db_VSysOrgAll);
		return "webbackground/sysorgmanagement/orgindex";
	}

}
